package com.halflife.framework.exception;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestController;

/**
 * Created by zhaoyf on 2018/3/17.
 */
@ControllerAdvice(annotations = RestController.class)
public class GlobleRestExceptionHandle {
    Logger logger = LoggerFactory.getLogger(GlobleRestExceptionHandle.class);
    @ExceptionHandler(Exception.class)
    public ResponseEntity<String> handle(Exception ex) {
        // ...
        logger.error("spring rest异常:"+ex.toString(),ex);
        return new ResponseEntity<String>("异常", HttpStatus.INTERNAL_SERVER_ERROR);
    }

}
